var t = require("../../requests/request.js"), a = getApp();

Page({
    data: {
        locateCity: "",
        currentCity: "",
        autoGovernment: null,
        cityList: null,
        provinceList: null,
        governmentName: "北京，天津，上海，重庆",
        numList: null,
        dataList: null,
        toNum: "",
        showList: null,
        params: null,
        winHeight: null
    },
    onLoad: function(t) {
        var a = this;
        wx.getSystemInfo({
            success: function(t) {
                a.setData({
                    winHeight: t.windowHeight
                });
            }
        }), a.setData({
            params: t
        }), a.loadCityData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    loadCityData: function() {
        var e = this, n = a.globalData.locateCityInfo, i = a.globalData.selectCityParams;
        void 0 == i.id && (i = n), e.setData({
            currentCity: i.name
        });
        var o = [], s = [];
        t.getCitys(function(t) {
            for (var a = [], r = [], u = [], l = 0, c = 0; c < t.length - 1; c++) {
                var d = t[c], m = d.EngName.substr(0, 1).toUpperCase();
                d.Initial = m;
                var g = e.data.governmentName.indexOf(d.CityName);
                g > -1 && 1 == d.CityLevel && o.push(d), g < 0 && 0 == d.ParentID && (s.push(d), 
                a[m] || (console.log("zimu:" + m + "---j:" + l), r.push(m), u[l] = !1, l++, a[m] = 1));
            }
            void 0 != i.index && (u[i.index] = !0, e.setData({
                toNum: r[i.numindex]
            })), console.log(e.data.toNum), e.setData({
                dataList: t,
                locateCity: n,
                numList: r,
                cityList: s,
                autoGovernment: o,
                showList: u
            });
        });
    },
    refreshLocateCity: function() {
        a.getLocateCity(), this.setData({
            locateCity: a.globalData.locateCityInfo
        });
    },
    redirectEvent: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.id, n = t.currentTarget.dataset.name, i = t.currentTarget.dataset.index, o = t.currentTarget.dataset.numindex, s = this.data.params, r = [];
        r.id = e, r.name = n, r.index = i, r.numindex = o, r.carid = s.carid, r.carname = s.carname, 
        r.img = s.img, a.setSelectCityParam(r), wx.navigateBack({
            url: "../price/price"
        });
    },
    clickCity: function(t) {
        for (var a = t.currentTarget.dataset.index, e = [], n = 0; n < this.data.showList.length; n++) e[n] = !1;
        e[a] = !0, this.setData({
            showList: e
        });
    },
    scrollNum: function(t) {
        var a = t.currentTarget.dataset.num;
        this.setData({
            toNum: a
        });
    },
    scrollToTop: function() {
        this.setData({
            toNum: "title"
        });
    },
    onPullDownRefresh: function() {
        this.loadCityData(), wx.stopPullDownRefresh();
    }
});